<?php

namespace app\partners\controller;

use app\common\controller\Adminbase;
use app\model\DistributionSetting;
use app\model\AgentShop;

class Shop extends Adminbase
{
    public function index()
    {
        $model = 'AgentShop';

        if ($this->request->isAjax()) {
            $map      = $this->buildParamsMap();
            $page     = input('page') ? input('page') : 1;
            $pageSize = input('limit') ? input('limit') : 20;

            $list  = AgentShop::where($map)
                ->field('*')
                ->withAttr('status', function ($value) {
                    $text = [1 => '邀请中', 2 => '已接受邀请', 3 => '已拒绝邀请', 4 => '取消邀请', 5 => '取消合作'];
                    return $text[$value];
                })
                ->page($page, $pageSize)
                ->select();
            $total = AgentShop::where($map)->count();

            $result = ["code" => 0, "count" => $total, "data" => $list];
            return json($result);
        }

        //生成列表数据
        $builder = new \app\common\controller\ListBuilder();
        $builder
            ->setDelBtn(false)
            ->setAddBtn(false)
            ->setDelAllBtn(false)
            ->setDataUrl()
            ->setFormUrl('')
            ->setSwitchTpl('amplifyTpl','image')
            ->setLimit()
            ->setModel($model)
            ->addTableCheckBox()
            ->setSwitchTpl('switchTpl', 'status')
            ->addTableColumn('id', '推客ID', 150, null, true)
            ->addTableColumn('name', '微信小店名称', 300)
            ->addTableColumn('appid', '微信小店ID', 300)
//            ->addTableColumn('image', '小店图标', null, '#amplifyTpl')
            ->addTableColumn('agent_id', '团长ID', 150)
            ->addTableColumn('status', '状态', 150)
            ->returnForm();

        $this->assign('module', 'app');
        return $this->fetch('admin@common/lists');
    }

}
